-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Parent Check Condition in buildTermsTree
#66006
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @yellowmastodon. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: 0 B Total Size: 1.81 MB ℹ️ View Unchanged
|
@@ -14,14 +14,16 @@ export function buildTermsTree( flatTerms ) { | |||
const flatTermsWithParentAndChildren = flatTerms.map( ( term ) => { | |||
return { | |||
children: [], | |||
parent: null, | |||
parent: undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Terms fetched by getEntityRecords use parent: undefined
, so we match them.
@@ -4,14 +4,14 @@ | |||
import { buildTermsTree } from '../terms'; | |||
|
|||
describe( 'buildTermsTree()', () => { | |||
it( 'Should return same array as input with null parent and empty children added if parent is never specified.', () => { | |||
it( 'Should return same array as input with undefined parent and empty children added if parent is never specified.', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we test both cases of null
and undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @torounit!
Left minor comment, but fix looks good to me ✅
packages/editor/src/utils/terms.js
Outdated
...term, | ||
}; | ||
} ); | ||
|
||
// All terms should have a `parent` because we're about to index them by it. | ||
if ( | ||
flatTermsWithParentAndChildren.some( ( { parent } ) => parent === null ) | ||
flatTermsWithParentAndChildren.some( | ||
( { parent } ) => parent === undefined || parent === null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which case will the parent: null
be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mamaduka I checked both HierarchicalTermSelector and PageAttributesParent and parent is undefined if parent does not exist. can we remove parent === null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we remove parent === null?
If it's never null
then I guess we can remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @torounit!
* Use undefined instead of null in `buildTermsTree` * allow null * use undefined * remove null checking
What?
The buildTermsTree function skips the process of converting terms into a tree structure if all terms in the passed array have no parent. Previously, this condition was determined by checking if
parent === null
, but it failed to evaluate correctly when parent was undefined. We will modify it to handle both null and undefined correctly.Why?
fix: #65704.
How?
Check
parent === undefiend
Testing Instructions
Try #65704.
Testing Instructions for Keyboard
Screenshots or screencast